package 剑指;

public class offer28 {
    class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }
    public boolean isSymmetric(TreeNode root) {
        // 防止root是空树
        if(root == null) return true;
        return isSameTree(root.left,root.right);
    }
    public boolean isSameTree(TreeNode A,TreeNode B) {
        // 同时为空才是true
        if(A == null && B ==null) return true;
        if(A == null || B == null) return false;
        // 当节点都不为空的时候,节点值不相等就是false;
        if(A.val != B.val) return false;
        return isSameTree(A.left,B.right) && isSameTree(A.right,B.left);
    }
}
